package org.lex.net;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

import org.lex.io.IO;


public class EchoRequestHandler implements RequestHandler {
	@Override
	public void respond(Socket client) throws IOException {
		OutputStream out = client.getOutputStream();
		InputStream in = client.getInputStream();
		byte[] buf = new byte[64];
		int len = 0;
		try {
			while ((len = in.read(buf)) != -1)
				out.write(buf, 0, len);
		} finally {
			IO.closeQuietly(in);
			IO.closeQuietly(out);
			client.close();
		}
	}
}
